extends NodeState


@export var enemy: BasicEnemy

var appear_time: float = 0.0
var modulate_color: Color = Color(1, 1, 1, 1)

func _on_process(delta : float) -> void:
	if _changing_state:
		return
	process_appear(delta)
	process_color()
	process_animation()


func _on_enter() -> void:
	appear_time = enemy.spawn_appear_time
	enemy.set_collision_disabled(true)


func process_animation():
	enemy.animationPlayer.play(BasicEnemy.ANIMATION_IDLE)


func process_appear(delta : float):
	if appear_time < 0.0:
		enemy.set_collision_disabled(false)
		transition.emit(BasicEnemy.STATE_WALK)
		return
	appear_time -= delta


func process_color():
	if appear_time < 0.0:
		enemy.modulate = Color.from_hsv(0, 0, 1.0)
	else:
		var v := remap(appear_time, enemy.spawn_appear_time, 0.0, 0.0, 1.0)
		enemy.modulate = enemy.modulate.lerp(modulate_color, clampf(v, 0, 1))
